<template>
  <div class="login-panel">
    <div class="title drag">EasyChat</div>
    <div class="login-form no-drag">
      <div class="error-msg"></div>
      <el-form :model="formData" :rules="rules" ref="formDataRef" label-width="0px" @submit.prevent>
        <el-form-item prop="email">
          <el-input size="large" clearable placeholder="请输入邮箱" v-model.trim="formData.email">
            <template #prefix>
              <span class="iconfont icon-email"></span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="nickname" v-if="!isLogin">
          <el-input size="large" clearable placeholder="请输入昵称" v-model.trim="formData.nickname">
            <template #prefix>
              <span class="iconfont icon-user"></span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input size="large" show-password clearable placeholder="请输入密码" v-model.trim="formData.password">
            <template #prefix>
              <span class="iconfont icon-password"></span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="repassword" v-if="!isLogin">
          <el-input size="large" show-password clearable placeholder="请再次输入密码" v-model.trim="formData.repassword">
            <template #prefix>
              <span class="iconfont icon-password"></span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="checkcode">
          <el-input size="large" show-password clearable placeholder="请输入验证码" v-model.trim="formData.checkcode">
            <template #prefix>
              <span class="iconfont icon-checkcode"></span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="loginbtn">
          <el-button type="primary" class="login-btn">{{isLogin?'登录':'注册'}}</el-button>
        </el-form-item>
        <div class="bottom-link">
          <span class="a-link" name="loginlink" @click="changOpType($event)">{{isLogin?'没有账号？':'已有账号？'}}</span>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { api } from "v-viewer";
import { ref, reactive, getCurrentInstance, nextTick } from "vue";
const { proxy } = getCurrentInstance();

const formData = ref({})
const formDataRef = ref()
const rules = {
  title: [{ required: true, messge: "请输入内容" }]
}

const isLogin = ref(true)

const changOpType = async (event) => {
  isLogin.value = !isLogin.value
  var prop = event.target.getAttributeNode('name')
  var value = '';
  if (prop) {
    value = prop.value
  }
  let args = {
    name: value,
    isLogin: isLogin.value
  }
  const res = await externalapi.calljson('onCppClick', args)
  console.log(res)
}

</script>

<style lang="scss" scoped>
.email-select {
  width: 250px;
}

.loading-panel {
  height: calc(100vh - 32px);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;

  img {
    width: 300px;
  }
}

.login-panel {
  background: #fff;
  border-radius: 5px;
  border: 2px solid #ddd;
  //box-shadow: 8px 8px 10px grey;

  .title {
    height: 30px;
    padding: 5px 0px 0px 10px;
  }

  .login-form {
    padding: 0px 15px 29px 15px;

    :deep(.el-input__wrapper) {
      box-shadow: none;
      border-radius: none;
    }
    .el-form-item {
      border-bottom: 1px solid #ddd;
    }
    .email-panel {
      align-items: center;
      width: 100%;
      display: flex;

      .input {
        flex: 1;
      }
      .icon-down {
        margin-left: 3px;
        width: 16px;
        cursor: pointer;
        border: none;
      }
    }
    .error-msg {
      line-height: 30px;
      height: 30px;
      color: #fb7373;
    }
    .check-code-panel {
      display: flex;
      .check-code {
        cursor: pointer;
        width: 120px;
        margin-left: 5px;
      }
    }
    .login-btn {
      margin-top: 20px;
      width: 100%;
      background: #07c160;
      height: 36px;
      font-size: 16px;
    }
    .bottom-link {
      text-align: right;
    }
  }
}
</style>